//
//  BgView.m
//  吃货·上海
//
//  Created by lanou on 15/11/25.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "BgView.h"
#import "UIImageView+WebCache.h"

@interface BgView ()<UIScrollViewDelegate>

@end
@implementation BgView

- (id)initWithFrame:(CGRect)frame url:(NSString *)url
{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat height = frame.size.height;
        CGFloat width = height;
        self.icon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
        //self.icon.center = CGPointMake(frame.size.width / 2, frame.size.height / 3);
        [self.icon sd_setImageWithURL:[NSURL URLWithString:url]];
        self.delegate = self;
        self.minimumZoomScale = 1;
        self.maximumZoomScale = 1.5;
        
        self.userInteractionEnabled = NO;
        [self addSubview:self.icon];
        
        
//        第一次手动调用动画方法
        [self performSelector:@selector(zoomAnimation) withObject:nil afterDelay:0];
        self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(zoomAnimation) userInfo:nil repeats:YES];
        
        
    }
    return self;
}

- (void)zoomAnimation
{
    [UIView animateWithDuration:3 animations:^{
        self.zoomScale = 1.5;
    } completion:^(BOOL finished) {
        if (finished) {
            [UIView animateWithDuration:3 animations:^{
                self.zoomScale = 1;
            }];
        }
    }];
}


//返回要放缩的视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.icon;
}


- (void)setModel:(DessertModel *)model
{
    _model = model;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:self.imageUrl]];
}



@end
